//
//  BaseViewController.m
//  ZHLY
//
//  Created by inphase on 16/11/18.
//  Copyright © 2016年 inphase. All rights reserved.
//

#import "BaseViewController.h"
#import <Objection.h>
#import <Colours.h>
#import "UIColor+GlobalColor.h"
#import <MBProgressHUD.h>
#import <SVProgressHUD.h>


@interface BaseViewController ()

@end

@implementation BaseViewController

objection_initializer(controller)

+(instancetype)controller {

    return [[[self class]alloc]init];
}

+(instancetype)controllerInStoryboard:(NSString *)storyboardName {
    return [[UIStoryboard storyboardWithName:storyboardName bundle:nil]instantiateViewControllerWithIdentifier:NSStringFromClass(self)];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    [self setAutomaticallyAdjustsScrollViewInsets:NO];
    
//    self.navigationBarHiddenStatus = self.navigationController.navigationBarHidden;
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    if (self.navigationController) {
        self.navigationController.navigationBar.barTintColor = [UIColor navibarColor];
        self.navigationController.navigationBar.tintColor = [UIColor blackColor];
        [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],}];
    }
    
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
}


-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}


-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
//    self.navigationController.navigationBarHidden = self.navigationBarHiddenStatus;
    
    [SVProgressHUD dismiss];
}

- (void)naviBackBtnClick {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)showMessage:(NSString *)message {
    if (!message || message.length == 0) {
        return;
    }
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = message;
    hud.label.textColor = [UIColor whiteColor];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.color = [[UIColor blackColor] colorWithAlphaComponent:0.65];
    hud.margin = 8.0f;
    hud.label.numberOfLines = 2;
    [hud hideAnimated:YES afterDelay:2];
}

- (void)showHUD {
    [SVProgressHUD show];
}

- (void)hiddenHUD {
    [SVProgressHUD dismiss];
}
- (void)showMBProgress{
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
}
- (void)hideMBProgress{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}

//强制旋转屏幕
- (void)orientationToPortrait:(UIInterfaceOrientation)orientation {
    SEL selector = NSSelectorFromString(@"setOrientation:");
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
    [invocation setSelector:selector];
    [invocation setTarget:[UIDevice currentDevice]];
    int val = orientation;
    [invocation setArgument:&val atIndex:2];//前两个参数已被target和selector占用
    [invocation invoke];
    
}

-(BOOL)shouldAutorotate {
    return NO;
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations {

    return UIInterfaceOrientationMaskPortrait;
}
+(instancetype)allocWithRouterParams:(NSDictionary *) params {
    return [self controller];
}

- (void)dealloc{
    NSLog(@"%s",__func__);
    
    
}

@end























